var SaturnTableVersion = {Version:"1.0"};
var SaturnTable = function(tableName,percount){
	this.currentIndex = 0; 
	this.tableName = tableName;
	this.currentpage = 0;
	this.showPagePilot(percount);
	this.bindTr('click',tableOnload);
};  

SaturnTable.prototype ={
	init:function (currentIndex){
		this.currentIndex = currentIndex;
		this.bindCursor(this.currentIndex);
	},
	bindTr:function(eventName,functionName) {
	   var items = $(this.tableName).getElementsByTagName("tr");
	   for(var i = 0; i < items.length; i++) {
              Event.observe(items[i],eventName,functionName,false);
       }
	},
	
	showPagePilot:function(percount){
      var trlen = $(this.tableName).getElementsByTagName("tr").length;
      for(var i=0;i<trlen;i++){
          $(this.tableName).getElementsByTagName("tr")[i].style.display="none";
      }  
               
       for(var j=this.currentpage*percount;j<(this.currentpage+1)*percount;j++){
          if($(this.tableName).getElementsByTagName("tr")[j]!=null){
         		 $(this.tableName).getElementsByTagName("tr")[j].style.display="";
           }
       }
       $(this.tableName + "count").innerHTML = Math.ceil(trlen/percount); 
       if(trlen<=percount){
        $(this.tableName+"nextPage").disabled = true;
       }
       this.bindCursorByIndex(this.currentpage*percount);
	},
	doIt:function(index,percount){
	    this.currentpage = this.currentpage+index;
  		var sum = $(this.tableName).getElementsByTagName("tr").length;
  		var pagecount = Math.ceil(sum/percount);
  		this.currentpage == (pagecount-1)?$(this.tableName+"nextPage").disabled = true:$(this.tableName+"nextPage").disabled = false;
        this.currentpage == 0?$(this.tableName+"upPage").disabled = true:$(this.tableName+"upPage").disabled = false;
  		this.showPagePilot(percount);
	
	},
	
	bindCursorByIndex:function(index) {
        var cursor = $(this.tableName).getElementsByTagName("tr");
        this.cleanAllCursor();
		this.currentIndex = index;
		//cursor[index].firstChild.innerHTML = "4";
		cursor[index].firstChild.className = "now_td";
		
	},
	
    bindCursorByElement:function(element) {
        var cursor = element;
        this.cleanAllCursor(); 
        if (cursor.firstChild.tagName =='TD') {
			//cursor.firstChild.innerHTML = "4";
			cursor.firstChild.className = "now_td";
		}
		else {
		    if(cursor.parentNode.firstChild.tagName=="TD"){
			//cursor.parentNode.firstChild.innerHTML = "4";
		 	cursor.parentNode.firstChild.className = "now_td";
		  }
		}
	},
	
	cleanAllCursor:function() {
	   var items = $(this.tableName).getElementsByTagName("tr");
	   for(var i = 0; i < items.length; i++) {
             	//items[i].firstChild.innerHTML = "&nbsp;";
             	items[i].firstChild.className = "";
             }
	}
};
